﻿using System;
using X.Entity;
using X.Web;
using System.Web.UI.HtmlControls;

namespace X.WebSite.Product
{
    public partial class Detail : PageBase
    {
        public ProductInfo _ProductInfo
        {
            get
            {
                ProductInfo productInfo;
                int productId = 0;

                string productName = string.Empty;
                if (!string.IsNullOrEmpty(Request.QueryString["ProductName"]))
                    productName = Request.QueryString["ProductName"];

                productName = X.Common.StringUtils.UrlToString(productName, ref productId);

                productInfo = (ProductInfo)ViewState[productName];

                if (null != productInfo)
                    return productInfo;

                if (0 != productId)
                    productInfo = Bll.Product.GetProduct(productId);
                else
                    productInfo = Bll.Product.GetProduct(productName);

                ViewState[productName] = productInfo;

                return productInfo;
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Title = X.Common.StringUtils.HtmlDecode(_ProductInfo.ProductName) + Title;

                this.lblProductName.Text = _ProductInfo.ProductName;
                this.lblModel.Text = _ProductInfo.Model;
                this.lblDescription.Text = _ProductInfo.ProductDescribe;
                this.lblPartNumber.Text = _ProductInfo.PartNumber;
                this.lblCertificate.Text = _ProductInfo.Certificate;
                this.lblColor.Text = _ProductInfo.Color;
                this.lblGuarantee.Text = _ProductInfo.Guarantee;
                this.lblHRC.Text = _ProductInfo.HRC;
                this.lblMaterial.Text = _ProductInfo.Material;
            }
        }

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);

            //Keywords
            HtmlMeta keywords = new HtmlMeta();
            keywords.Name = "keywords";
            keywords.Content = _ProductInfo.Keyword;
            Header.Controls.Add(keywords);

            //Description
            HtmlMeta description = new HtmlMeta();
            description.Name = "description";
            description.Content = _ProductInfo.Description;
            Header.Controls.Add(description);
        }
    }
}